﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace My3DGame
{
    public class clsMenuManager
    {
        clsMenu currentMenu;
        public clsMenu CurrentMenu
        {
            get { return currentMenu; }
            set { currentMenu = value; }
        }

        public clsMenuManager(clsMenu menu)
        {
            CurrentMenu = menu;
        }

        //
        public clsMenuManager(string menuFile)
        {
            CurrentMenu = clsMenu.LoadFromXML(menuFile);
        }

        #region Xử lý menu theo các sự kiện
        // Note for me: Viết cho cả bàn phím và gamepad.

        public void EnterSubMenu(clsMenu subMenu)
        {
            subMenu.ParentItems = currentMenu;
            currentMenu = subMenu;
            currentMenu.ChoiceIndex = 0;
        }

        public void EnterSubMenu(int subMenuIndex)
        {
            clsMenu temp = CurrentMenu.SubItems[subMenuIndex];
            if (temp.SubItems.Count != 0)
            {
                EnterSubMenu(temp);
            }
        }

        public void BackToParentsMenu()
        {
            if (currentMenu.ParentItems != null)
            {
                currentMenu = currentMenu.ParentItems;
            }
        }

        public void ChooseUpperObject()
        {
            CurrentMenu.ChoiceIndex--;
            if (CurrentMenu.ChoiceIndex < 0)
                CurrentMenu.ChoiceIndex = CurrentMenu.SubItems.Count - 1;
        }
        public void ChosseLowerObject()
        {
            CurrentMenu.ChoiceIndex++;
            if (CurrentMenu.ChoiceIndex == CurrentMenu.SubItems.Count)
                CurrentMenu.ChoiceIndex = 0;
        }

        #endregion
    }
}
